package hivi.vn.hivigold.adapters;

import hivi.vn.hivigold.R;
import hivi.vn.hivigold.objects.Report;
import hivi.vn.hivigold.utils.Formats;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class BuyAdapter extends BaseAdapter {
	ArrayList<Report> arr;
	Context context;
	public BuyAdapter(Context c, ArrayList<Report> arr) {
		// TODO Auto-generated constructor stub
		this.context = c;
		this.arr = arr;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arr.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arr.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		View v = arg1;
		BuyHolder bh;
		if(v==null)
		{
			v = ((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.detail_report_doanhthu, null);
			bh = new BuyHolder();
			bh.txtNhom_hang = (TextView)v.findViewById(R.id.tvd_Nhomhang);
			bh.txtMa_hang = (TextView)v.findViewById(R.id.tvd_Ma_hang);
			bh.txtTen_hang = (TextView)v.findViewById(R.id.tvd_Ten_hang);
			bh.txtDvt = (TextView)v.findViewById(R.id.tvd_Dvt);
			bh.txtCode = (TextView)v.findViewById(R.id.tvd_code);
			bh.txtSl = (TextView)v.findViewById(R.id.tvd_sl);
			bh.txtGia_ban = (TextView)v.findViewById(R.id.tvd_gia_ban);
			bh.txtTien_ban = (TextView)v.findViewById(R.id.tvd_tien_ban);
			bh.txtGia_von = (TextView)v.findViewById(R.id.tvd_gia_von);
			bh.txtTien_von = (TextView)v.findViewById(R.id.tvd_tien_von);
			bh.txtLai = (TextView)v.findViewById(R.id.tvd_lai);
			v.setTag(bh);
		}else
		{
			bh = (BuyHolder)v.getTag();
		}
		Report r = arr.get(arg0);
		bh.txtNhom_hang.setText(r.getNhom_hang());
		bh.txtNhom_hang.setVisibility(View.GONE);
		bh.txtMa_hang.setText(r.getMa_hang());
		bh.txtTen_hang.setText(r.getTen_hang());
		bh.txtDvt.setText(r.getDvt());
		bh.txtCode.setText(r.getCode());
		bh.txtSl.setText(Formats.number(r.getSl_ban()));
		bh.txtGia_ban.setText(Formats.money(r.getGia_ban()/1000));
		bh.txtTien_ban.setText(Formats.money(r.getTien_ban()/1000));
		bh.txtGia_von.setText(Formats.money(r.getGia_von()/1000));
		bh.txtTien_von.setText(Formats.money(r.getTien_von()/1000));
		bh.txtLai.setText(Formats.money(r.getLai()/1000));
		return v;
	}

	static class BuyHolder
	{
		TextView txtNhom_hang;
		TextView txtMa_hang;
		TextView txtTen_hang;
		TextView txtDvt;
		TextView txtCode;
		TextView txtSl;
		TextView txtGia_ban;
		TextView txtTien_ban;
		TextView txtGia_von;
		TextView txtTien_von;
		TextView txtLai;
	}
}
